package com.codi.api.xxljob;

import com.codi.bus.core.service.impl.BusinessIncomeService;
import com.codi.bus.core.service.impl.LocaldataProfitService;
import com.codi.bus.core.service.impl.LocaldataTradeOrderService;
import com.codi.bus.core.service.impl.LocaldataUserShareService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author lvgo
 * @version 1.0
 * @Description: 基金资产同步
 * 0 30 2 * * ?
 * @date 18-6-29 下午4:43
 */
@Slf4j
@Component
@JobHandler("assetsHandler")
public class AssetsHandler extends IJobHandler {
    @Resource
    private LocaldataUserShareService localdataUserShareService;

    @Resource
    private LocaldataProfitService localdataProfitService;

    @Resource
    private LocaldataTradeOrderService localdataTradeOrderService;

    @Resource
    private BusinessIncomeService businessIncomeService;

    @Override
    public ReturnT<String> execute(String s) throws Exception {
        log.info("assets job");

        log.info("refresh AssetsJob ");

        //用户份额  目前 全量更新  调恒生
        localdataUserShareService.init();

        // 日收益  根据份额 不调恒生
        localdataProfitService.execProfit();
        //更新交易申请   调恒生
        localdataTradeOrderService.updateOrder(false);
        //业务净收入  每日更新  不会调恒生   根据订单和份额
        log.info("业务收入 ");

        businessIncomeService.exec();
        XxlJobLogger.log("Assets-JOB, success");

        return SUCCESS;
    }
}
